<template>
  <div class="loginBox">
    <h2 class="title">欢迎登录</h2>
    <el-form label-width="80px">
      <el-form-item label="账号" class="fffitem">
        <el-input v-model="user" placeholder="请输入内容" minlength="6"></el-input>
      </el-form-item>
      <el-form-item label="密码" class="fffitem">
        <el-input placeholder="请输入密码" v-model="password" show-password minlength="6"></el-input>
      </el-form-item>
    </el-form>
    <div style="text-align:center">
      <el-button type="primary" @click="savelogin">登录</el-button>
    </div>
    <p class="goregister">
      <router-link tag="span" to="/register">
        去注册
        <i class="el-icon-right"></i>
      </router-link>
    </p>
  </div>
</template>

<style lang="less">
.loginBox {
  width: 100%;
  height: 100%;
  background-image: url("./../../assets/background.jpg");
  background-size: 100% 100%;
}
.title {
  font-size: 0.2rem;
  color: #fff;
  text-align: center;
  padding: 150px 0 20px 0;
}
form {
  width: 90%;
  text-align: center;
}
.fffitem .el-form-item__label {
  color: #fff !important;
}
.goregister {
  text-align: right;
  color: #fff;
  padding: 20px 20px 0 0;
}
</style>

<script>
import { mapState } from "vuex";
export default {
  data: function() {
    return {
      user: "",
      password: ""
    };
  },
  computed: {
    ...mapState("userStore", ["userList"])
  },
  methods: {
    savelogin() {
      let that = this;
      let lsobj = this.userList.filter(item => {
        return item.user == that.user;
      });
      console.log(lsobj);
      if (lsobj.length > 0) {
        if (lsobj[0].password == that.password) {
          this.$message({
            type: "success",
            message: "登陆成功",
            duration: 500
          });
          localStorage.setItem("userlist", JSON.stringify(lsobj[0]));
          that.$router.push("/home");
        }
      }
    }
  }
};
</script>